package com.xly.webclick.utils;

import android.content.Context;

/**
 * Created by amos on 2018/6/4.
 */

public class DisplayUtils {

    private static int DISPLAY_WIDTH;

    private static int DISPLAY_HEIGHT;

    private static int SYSTEM_BAR_HEIGHT;

    public final static void install(Context context) {
        if (context != null) {
            DISPLAY_WIDTH = context.getResources().getDisplayMetrics().widthPixels;
            DISPLAY_HEIGHT = context.getResources().getDisplayMetrics().heightPixels;
            SYSTEM_BAR_HEIGHT = getStatusBarHeight(context);
        }
    }

    public final static int getDisplayWidth() {
        return DISPLAY_WIDTH;
    }

    public final static int getDisplayHeight() {
        return DISPLAY_HEIGHT;
    }

    public final static int getSize(int px) {
        float degree = px / 750.000f;
        return (int) (DISPLAY_WIDTH * degree);
    }

    public final static int getSystemBarHeight() {
        return SYSTEM_BAR_HEIGHT;
    }

    private static int getStatusBarHeight(Context activity) {
        int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
        return activity.getResources().getDimensionPixelOffset(resourceId);
    }
}
